import {deleteAction, getAction, postAction, downFile, getFileAccessHttpUrl} from '@/api/request'

export const application12 = {

    data() {
        // 重复银行卡账号验证
        const ssca0011AgainCheck = async (rule, value, callback) => {
            if (!this.formValidate.ssca0011_again) {
                return callback(new Error('请再次输入银行卡账号！'));
            }
            else if (this.formValidate.ssca0011 != this.formValidate.ssca0011_again) {
                return callback(new Error('两次输入银行卡账号不一致！'));
            } else {
                callback()
            }
        };
        const validateSsca0026 = (rule, value, callback) => {
            if (!this.formValidate.ssca0026 && rule.required) {
                callback(new Error('请输入总保障金额'));
            } else {
                callback();
            }
        };
        return {
            url: {
                tab12Infor: "/api/ac/subsistence/ss12007Service/saveTab12Infor",
                tab12Submit: "/api/ac/subsistence/ss12007Service/insertTab12",
                getMemberList: "/api/ac/subsistence/ss12007Service/getMemberList"
            },
            memberList: [],
            formValidate: {},
            Loading: false,
            information: "",
            ruleValidate: {
                ssca0044: [
                    {required: true, message: '家庭月基础收入金额不能为空!', trigger: 'blur', type: "number"}
                ],
                ssca0051: [
                    {required: true, message: '家庭人口数不能为空!', trigger: 'blur', type: "number"}
                ],
                ssca0052: [
                    {required: true, message: '保障人口数不能为空!', trigger: 'blur', type: "number"}
                ],
                ssca0026: [
                    {required: true, trigger: 'blur', validator: validateSsca0026}
                ],
                ssca0013: [
                    {required: true, message: '请选择致贫原因！', trigger: 'change'}
                ],
                ssca0009: [
                    {required: true, message: '请选择开户银行名称！', trigger: 'change'}
                ],
                ssca0082: [
                    {required: true, message: '请选择是否代领！', trigger: 'change'}
                ],
                ssca0010: [
                    {required: true, message: '开户人姓名不能为空！', trigger: 'blur'}
                ],
                ssca0083: [
                    {required: true, message: '请输入正确的开户人证件号码！', trigger: 'blur'}
                ],
                ssca0011: [
                    {required: true, message: '请输入正确的银行账号！', trigger: 'blur'}
                ],
                ssca0011_again: [
                    {required: true, message: '', validator: ssca0011AgainCheck, trigger: 'blur'}
                ],
                ssca0003: [
                    {required: true, message: '申请时间不能为空！', trigger: 'change', type: "date"}
                ],
                ssca0008: [
                    {required: true, message: '救助申请理由不能为空！', trigger: 'blur'}
                ],
            },

        }
    },
    methods: {
        //提交申请
        prevStep() {
            this.$emit('prevStep')
        },
        changeSsca0082() {
            this.formValidate.ssca0083 = "";
            this.formValidate.ssca0010 = "";
        },
        changeSsca0010(obj) {
            this.$set(this.formValidate, "ssca0083", obj);
        },
        nextStep() {
            this.Loading = true;
            var that = this;
            this.$refs['formValidate'].validate((valid) => {
                if (valid) {
                    postAction(that.url.tab12Submit, this.formValidate).then((res) => {
                        if (res.data.errcode == 0) {
                            that.$Message.success("提交申请成功！");
                            that.$emit('finish');
                        } else {
                            that.$Message.error(res.data.errmsg);
                        }
                    }).finally(() => {
                        that.Loading = false;
                    });
                } else {
                    that.Loading = false;
                }
            })
        },
        getTab12Infor() {
            var that = this;
            var ss12007 = new Object();
            ss12007.ssca0001 = this.$parent.familyInfo.ss11301Id;
            ss12007.ssca0043 = this.$parent.familyInfo.azdf0007;
            ss12007.azcp0001 = this.$parent.familyInfo.azcp0001;
            ss12007.azcp0003 = this.$parent.familyInfo.azcp0003;
            ss12007.id = this.$parent.familyInfo.ss12007Id;
            postAction(that.url.tab12Infor, ss12007).then((res) => {
                if (res.data.errcode == 0) {
                    that.information = res.data.data.information;
                    that.formValidate = res.data.data.ss12007;
                    if (that.formValidate.ssca0003) {
                        this.$set(this.formValidate, "ssca0003", this.DateFormat(that.formValidate.ssca0003, 'YYYY-MM-DD'));
                    } else {
                        this.$set(this.formValidate, "ssca0003", "");
                    }
                    this.$parent.familyInfo.ss12007Id = res.data.data.ss12007.id;
                } else {
                    that.$Message.error(res.data.errmsg);
                }
            }).finally(() => {
                that.Loading = false;
            });
        },
        //获取家庭成员信息
        getMemberList() {
            var that = this;
            postAction(that.url.getMemberList, {azcp0500: this.$parent.familyInfo.ss11301Id}).then((res) => {
                if (res.data.errcode == 0) {
                    that.memberList = res.data.data;
                } else {
                    that.$Message.error(res.data.errmsg);
                }
            }).finally(() => {
                that.Loading = false;
            });
        }
    }
}
